import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache 			= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		taps:[],
		forms: [
			{ label: '项目名称',		name: 'kind_name', type:'select' },
			{ label: '项目代码',		name: 'kind_code' },
			{ label: '创建时间',  	names: ['start_date','end_date'], type:'date-range' },
		]
	}
	
	model = {}
	
	componentDidMount(){
		this.getSelect()
		if(window.isInit){
		  this.fetch()
		}
	}
	
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		
		$cache.then( async f => {
			// 项目名称
			$fn.setRow(forms, 'kind_name',  await f.getCache({ api:'common/getKindList4Select', param:{category: 'Y,Z,D'},way:'get',refresh:true }))
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'st-cs-kind/index', { isIndex:true })
	
	cols = [
		{ title: '项目名称', 	dataIndex: 'kind_name', width:300 },
		{ title: '项目代码', 	dataIndex: 'kind_code', width:130 },
		{ title: '项目数量', 	dataIndex: 'kind_num', ...$fn.table.num },
		{ title: '统计时间', 	dataIndex: 'st_time', 	...$fn.table.date },
	]
	
	render(){
		return (
			<>
				{/* 搜索 */}
				{ SearchForm.call(this) }
				{/* 表格 */}
				{ Table.call(this, { isIndex:true, isInit: window.isInit }) }
			</>
		)
	}
}

export default Index